package com.yitiao.config;

import com.yitiao.annotation.DataSource;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
class DataSourceAspect {

    @Before("@annotation(dataSource)")
    public void beforeSwitchDataSource(DataSource dataSource) {
        DataSourceHandler.changeDataSource(dataSource.value());
    }

    @After("@annotation(com.yitiao.annotation.DataSource)")
    public void afterSwitchDataSource() {
        DataSourceHandler.clearDataSource();
    }
}
